package com.warmguard.core.controlller;

import com.warmguard.core.core.vo.Result;
import com.warmguard.core.domain.dto.ForumPostsDTO;
import com.warmguard.core.domain.entity.ForumPosts;
import com.warmguard.core.service.ForumPostsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: CommunityController
 * PackageName: com.warmguard.core.controlller
 * Description:
 *
 * @Author: 32782
 * @Date: 2025/2/24 下午9:51
 * @Version: 1.0
 */
@RequestMapping("/member/community")
@RestController
public class CommunityController {

    @Autowired
    private ForumPostsService forumPostsService;

    @PostMapping("/publish")
    public Result publish(@RequestBody ForumPostsDTO forumPostsDTO) {
        ForumPosts forumPosts = new ForumPosts();

        BeanUtils.copyProperties(forumPostsDTO, forumPosts);
        forumPostsService.save(forumPosts);
        return Result.ok();
    }

    @GetMapping("/list")
    public Result list() {
        List<ForumPosts> forumPostsList = forumPostsService.list();
        return Result.ok(forumPostsList);
    }

    @GetMapping("/detail")
    public Result detail(@RequestParam(value = "id") int id) {
        ForumPosts forumPosts = forumPostsService.getById(id);
        return Result.ok(forumPosts);
    }
}
